﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;

namespace WPFExcelReport
{
    public partial class TRWBBS13
    {
        #region ==AUF===========
        public static readonly DependencyProperty AUFProperty = DependencyProperty.Register("AUF",
            typeof(string), typeof(TRWBBS13),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAUFChanged));
        public string AUF
        {
            get
            {
                return (string)GetValue(AUFProperty);
            }
            set
            {
                SetValue(AUFProperty, value);
                OnAUFChg(value);
            }
        }
        private static void OnAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TRWBBS13;
            if (src != null)
            {
                src.AUF = (string)e.NewValue;
            }
        }
        #endregion
        
        public TRWBBS13()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWBBEW();
            this.DataContext = MV;
            InitializeComponent();
           
        }

        public virtual void OnAUFChg(string auf)
        {
            TBMain.Clear();
            if (auf.Length < 32)
                return;
            dwData = TBMain.NewRow();
            dwData["WBEWMANDANT"] = app.Mandant;
            dwData["WBEWART"] = " AND WBEWART = '" + auf.Substring(0, 20) + "' AND WBEWVAR='"+auf.Substring(20,2) +"' AND WBEWFARBE='"+auf.Substring(22,10)+"'";
            dwData["WBEWFILLER"] = " AND WBEWBUCHDAT>=" + DTSTART + " AND WBEWBUCHDAT< " + DTEND;
            SResult = ((VWBBEW)MV).QueryWBBEW(dwData, 11);
            MergeData(SResult, true, true);
        }
        
    }
}
